function loadajax(url){
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('mainbody').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}

function loadheader(url){
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('navigatortab').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}

function postwall(url){
    var content = document.getElementById('whatisonyourmind').value;
    var fullurl = url + "/" + content;
    
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('mainbody').innerHTML=xmlhttp.responseText;
			
        }else{
    }
    }
    xmlhttp.open('POST', fullurl, true);
    xmlhttp.send();
}

function newmessage(url){
	
    var msubject = document.getElementById('msubject').value;
    var mcontent = document.getElementById('mcontent').value;
    var mto = document.getElementById('mto').value;
    var params ="msubject="+encodeURIComponent(msubject)+"&mcontent="+encodeURIComponent(mcontent)+"&mto="+encodeURIComponent(mto);
	
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('mainbody').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open('POST', url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);
}

function uploadphoto(){
}

function timeloadnotiffollow(url)
{
    var xmlhttp;
    var t;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('notif').innerHTML=xmlhttp.responseText;
            
        }else{
            //clearTimeout(t);
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    t = setTimeout(function() { timeloadnotiffollow(url) }, 5000);
    //t = setTimeout(timeloadnotiffollow(url),5000);
}
function loadnotiffollow(url){
    var timer_is_on=0;
	
    if (!timer_is_on)
    {
        timer_is_on=1;
        timeloadnotiffollow(url);
    }
}

function markasreadnotiffollow(url){
    alert("mark as read");
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('notificationfollowbox').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}


function timeloadnotiftag(url)
{
    var xmlhttp;
    var t;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('notificationtagbox').innerHTML=xmlhttp.responseText;
            //t = setTimeout(timeloadnotiftag(url),5000);
        }else{
            //clearTimeout(t);
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    t = setTimeout(function() { timeloadnotiftag(url) }, 5000);
    //t = setTimeout(timeloadnotiftag(url),5000);

}
function loadnotiftag(url){
    var timer_is_on=0;
	
    if (!timer_is_on)
    {
        timer_is_on=1;
        timeloadnotiftag(url);
    }
}

function markasreadnotiftag(url){
    alert("mark as read");
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('notificationtagbox').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}

function postfb_uploadphoto(username, filename){
    FB.init({
        appId:'139497769453142',
        cookie:true,
        status:true,
        xfbml:true
    });

    FB.ui({
        method: 'feed',
        message: username + ' telah mengupload photo ' + filename
        });
}

function postfb_registration(username){
    FB.init({
        appId:'139497769453142',
        cookie:true,
        status:true,
        xfbml:true
    });

    FB.ui({
        method: 'feed',
        message: username + ' telah berhasil melakukan registrasi'
        });
}

//chat
function ajaxRequest(){
    var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] ;
    if (window.ActiveXObject){
        for (var i=0; i<activexmodes.length; i++){
            try{
                return new ActiveXObject(activexmodes[i]);
            }
            catch(e){
            }
        }
    }
    else if (window.XMLHttpRequest)
        return new XMLHttpRequest();
    else
        return false;
}

function ajaxPost(url){
    // check if the text box has an input as message if not end the function.
    var msgvalue=encodeURIComponent(document.getElementById("chat").value);
    if (msgvalue.length < 1)
    {
        return false;
    }
    var parameters="msg="+msgvalue;
    msgvalue=encodeURIComponent(document.getElementById("chatto").value);
    parameters+="&chatto="+msgvalue;
    // proceed with the ajax post request;
    var mypostrequest = new ajaxRequest();
    mypostrequest.onreadystatechange=function(){
        if (mypostrequest.readyState==4){
            if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
                document.getElementById("SystemMsgs").innerHTML=mypostrequest.responseText;
            }
            else{
                alert("An error has occured making the request");
            }
        }
    }
    mypostrequest.open("POST", url, true);
    mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    mypostrequest.send(parameters);
}
function ajaxGet(url)
{
    var t;
    var mygetrequest  = new ajaxRequest();
    if (mygetrequest)
    {
        mygetrequest.onreadystatechange = function(){
            if (mygetrequest.readyState==4 && mygetrequest.status==200)
            {
                document.getElementById('ReloadThis').innerHTML = mygetrequest.responseText;
                //setTimeout(function() {ajaxGet(url);}, 500);
            }
        };
        mygetrequest.open('GET', url, true);
        mygetrequest.send(null);
    }
    t = setTimeout(function() { ajaxGet(url) }, 500);
}
function loadConv(url){
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById('chat-box').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}